# -*- coding: UTF-8 -*-
__author__ = 'Jeffrey'

from django.http import HttpResponseRedirect


def do_logging(*args):
    print args


def login(func):
    '''
    验证用户是否登录装饰器
    :param func:
    :return:
    '''
    def wrapper(*args, **kw):
        if args[0].session.get('webStatus') == "HasLogin":
            do_logging("error", "Has Login!")
            return func(*args, **kw)
        else:
            do_logging("error", "Not Login!")
            return HttpResponseRedirect('/account/login_page/')

    return wrapper

# 文件上传
def handle_uploaded_file(f, absolute_path_filename):
    info = open(absolute_path_filename, 'wb+')
    for chunk in f.chunks():
        info.write(chunk)
    info.close()
    return info